using System;
using System.Collections.Generic;

public class StandardChessBoard : BaseFunctionalChessBoard
{
    private Dictionary<int, (Pos, (Pos, Pos))> campForwardOrientationDict = new Dictionary<int, (Pos, (Pos, Pos))>()
    {
        [0] = (new Pos(0, 1), (new Pos(-1, 0), new Pos(1, 0))),
        [1] = (new Pos(0, -1), (new Pos(-1, 0), new Pos(1, 0)))
    };
    public StandardChessBoard() : this(false)
    {

    }
    protected override BaseFunctionalChessBoard GetUninitializedInstance()
    {
        return new StandardChessBoard(true);
    }
    private StandardChessBoard(bool skipDefaultInit)
    {
        grids = new StandardGrid[9, 10];
        for (int i = 0; i < grids.GetLength(0); i++)
        {
            for (int j = 0; j < grids.GetLength(1); j++)
            {
                Pos pos = new Pos(i, j);
                int camp = (j < 5) ? 0 : 1;
                bool isPalace = (i >= 3 && i <= 5 && ((j >= 0 && j <= 2) || (j >= 7 && j <= 9))) ? true : false;
                grids[i, j] = new StandardGrid(pos, camp, isPalace);
            }
        }
        List<int> campTeamList = new List<int>() { 0, 1 };
        List<(Pos, Type, int)> chessTypeCampList = new List<(Pos, Type, int)>()
        {
            (new Pos(0, 3),typeof(ChessBing),0),
            (new Pos(2, 3),typeof(ChessBing),0),
            (new Pos(4, 3),typeof(ChessBing),0),
            (new Pos(6, 3),typeof(ChessBing),0),
            (new Pos(8, 3),typeof(ChessBing),0),
            (new Pos(1, 2),typeof(ChessPao),0),
            (new Pos(7, 2),typeof(ChessPao),0),
            (new Pos(0, 0),typeof(ChessChe),0),
            (new Pos(8, 0),typeof(ChessChe),0),
            (new Pos(1, 0),typeof(ChessMa),0),
            (new Pos(7, 0),typeof(ChessMa),0),
            (new Pos(2, 0),typeof(ChessXiang),0),
            (new Pos(6, 0),typeof(ChessXiang),0),
            (new Pos(3, 0),typeof(ChessShi),0),
            (new Pos(5, 0),typeof(ChessShi),0),
            (new Pos(4, 0),typeof(ChessShuai),0),

            (new Pos(0, 6),typeof(ChessBing),1),
            (new Pos(2, 6),typeof(ChessBing),1),
            (new Pos(4, 6),typeof(ChessBing),1),
            (new Pos(6, 6),typeof(ChessBing),1),
            (new Pos(8, 6),typeof(ChessBing),1),
            (new Pos(1, 7),typeof(ChessPao),1),
            (new Pos(7, 7),typeof(ChessPao),1),
            (new Pos(0, 9),typeof(ChessChe),1),
            (new Pos(8, 9),typeof(ChessChe),1),
            (new Pos(1, 9),typeof(ChessMa),1),
            (new Pos(7, 9),typeof(ChessMa),1),
            (new Pos(2, 9),typeof(ChessXiang),1),
            (new Pos(6, 9),typeof(ChessXiang),1),
            (new Pos(3, 9),typeof(ChessShi),1),
            (new Pos(5, 9),typeof(ChessShi),1),
            (new Pos(4, 9),typeof(ChessShuai),1),
        };
        fieldInfo = new FieldInfo(campTeamList, chessTypeCampList, this);
        if (!skipDefaultInit)
        {
            fieldInfo.Init(chessTypeCampList, this);
        }
    }
    public Pos GetForwardDirectionByCamp(int camp)
    {
        if (!campForwardOrientationDict.ContainsKey(camp))
        {
            throw new Exception();
        }
        return campForwardOrientationDict[camp].Item1;
    }
    public Pos GetOrientation1DirectionByCamp(int camp)
    {
        if (!campForwardOrientationDict.ContainsKey(camp))
        {
            throw new Exception();
        }
        return campForwardOrientationDict[camp].Item2.Item1;
    }
    public Pos GetOrientation2DirectionByCamp(int camp)
    {
        if (!campForwardOrientationDict.ContainsKey(camp))
        {
            throw new Exception();
        }
        return campForwardOrientationDict[camp].Item2.Item2;
    }
}
